package com.eastfair.venueservice.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.eastfair.annotation.annotation.security.PreAuth;
import com.eastfair.boot.controller.SuperController;
import com.eastfair.boot.request.PageParams;
import com.eastfair.core.base.R;
import com.eastfair.echo.core.EchoService;
import com.eastfair.venueservice.dto.ServiceOrderOperateLogDTO;
import com.eastfair.venueservice.dto.ServiceOrderOperateLogPageQuery;
import com.eastfair.venueservice.dto.ServiceOrderOperateLogSaveDTO;
import com.eastfair.venueservice.dto.ServiceOrderOperateLogUpdateDTO;
import com.eastfair.venueservice.entity.ServiceOrderOperateLog;
import com.eastfair.venueservice.service.ServiceOrderOperateLogService;
import com.eastfair.venueservice.vo.ServiceOrderOperateLogVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;


/**
 * <p>
 * 前端控制器
 * 服务订单操作记录
 * </p>
 *
 * @author dqq
 * @date 2022-12-16
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/serviceOrderOperateLog")
@Api(value = "ServiceOrderOperateLog", tags = "服务订单操作记录")
@PreAuth(replace = "venueservice:serviceOrderOperateLog:")
public class ServiceOrderOperateLogController extends SuperController<ServiceOrderOperateLogService, Long, ServiceOrderOperateLog, ServiceOrderOperateLogPageQuery, ServiceOrderOperateLogSaveDTO, ServiceOrderOperateLogUpdateDTO> {

    @Resource
    private EchoService echoService;

    @Resource
    private ServiceOrderOperateLogService serviceOrderOperateLogService;

    @Override
    public void handlerResult(IPage<ServiceOrderOperateLog> page) {
        // 想让返回值实现自动回显，请将此行代码打开
        // echoService.action(page);
    }

    /**
     * Excel导入后的操作
     *
     * @param list
     */
    @Override
    public R<Boolean> handlerImport(List<Map<String, String>> list){
        List<ServiceOrderOperateLog> serviceOrderOperateLogList = list
                .stream()
                .map((map) -> ServiceOrderOperateLog.builder().build())
                .collect(Collectors.toList());
        return R.success(baseService.saveBatch(serviceOrderOperateLogList));
    }

    /**
     * 处理参数
     *
     * @param params 分页参数
     */
    @Override
    public void handlerQueryParams(PageParams<ServiceOrderOperateLogPageQuery> params) {
        ServiceOrderOperateLogPageQuery pageQuery = params.getModel();
    }

    /**
     * 分页查询订单操作记录VO列表.
     *
     * @param pageParams the page params
     * @return the r
     */
    @ApiOperation("分页查询订单操作记录VO列表")
    @PostMapping("/query/serviceOrderOperateLog")
    public R<Page<ServiceOrderOperateLogVO>> queryServiceOrderOperateLog(@RequestBody PageParams<ServiceOrderOperateLogDTO> pageParams) {
        log.info("queryServiceOrderOperateLog - 分页查询订单操作记录VO列表, pageParams={}", pageParams);
        return R.successDef(serviceOrderOperateLogService.listServiceOrderOperateLogVO(pageParams));
    }
}
